package hasthi.tools;

import hasthi.common.HasthiException;
import hasthi.common.HasthiException.FaultCode;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropEditor {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws Exception {
        if(args.length < 2){
            throw new HasthiException("found "+args.length
                    +" arguments PropEditor <propfile> <popname>=<value>",FaultCode.ConfigError);
        }
        Properties properties = new Properties();
        FileInputStream in = new FileInputStream(args[0]);
        properties.load(in);
        in.close();
        //
        for(int i=1;i<args.length;i++){
            if(args[i].indexOf("=") > 0){
                String[] props = args[i].split("=");
                System.out.println("set "+args[i]);
                properties.setProperty(props[0], props[1]);
            }
        }
        FileOutputStream out = new FileOutputStream("hasthi.properties");
        properties.store(out,"updated by PropEditor");
    }

}
